#include "NumericalBitmapFont.h"
#include <string>

using namespace std;

NumericalBitmapFont::NumericalBitmapFont(const char* filename) : Image(filename, ColourKey(0,0,0))
{
}

NumericalBitmapFont::~NumericalBitmapFont()
{
}

void NumericalBitmapFont::drawNumber(int x, int y, unsigned int number)
{
	int length = (int) log10f((float)number);

	SDL_Rect source;
	source.x = 0;
	source.y = 0;
	source.w = 9;
	source.h = 10;

	SDL_Rect destination;
	destination.x = x;
	destination.y = y;
	destination.w = 9;
	destination.h = 10;

	if(number == 0)
	{
		draw(&destination, &source);
		return;
	}

	for(int i = length; i >= 0; i--)
	{
		int divisor = (int)pow(10.0f, i);
		int n = (number / divisor);
		number -= n * divisor;

		source.x = n * source.w;

		draw(&destination, &source);

		destination.x += destination.w;
	}
}
